﻿@model BuyThePeople.Models.T_GOODS

@{
    ViewBag.Title = "Make";
}

    <div class="main_container">
		<div id="content">
			<div>
				<div style="margin:30px;">
					<p style="font-size:20pt;" >공동구매 생성하기 </p>				
				</div>
				<div>
					<hr style="width:920px" />
				</div>
			</div>
@using (Html.BeginForm("Make", "Goods", FormMethod.Post, new { onsubmit="return formSubmit();", style="asd"}))
{
    @Html.ValidationSummary(true)

			<div style="margin:30px;">			
				<div>
					<div>                        
                        <p class="help-block">
                            <a id="goodsSearch" href="/Goods/APISearch" target="_blank" onclick="return false;" class="btn">상품검색</a>
                            <span>상품을 선택해주세요.</span>
                        </p>
						@Html.HiddenFor(model => model.Title)
                        @Html.HiddenFor(model => model.Image)
                        @Html.HiddenFor(model => model.Link)
                        @Html.HiddenFor(model => model.LowPrice)
					</div>
				</div>
				<div id="selected" style="display:none;">
                    <table>
                                <tr>
                                    <td rowspan="3"><img id="prd_image" src="" alt="상품이미지" /></td>
                                    <td><span style="font-size:14pt; margin-left:80px;">공구상품 : </span><span id="prd_title" style="font-size:13pt; font-weight:bold"></span></td>
                                </tr>
                                <tr>                                    
                                    <td><span style="font-size:14pt; margin-left:80px;">상품가격 : </span><span id="price_min" style="font-size:13pt; color:#ff6000; font-weight:bold"></span></td>
                                </tr>
                                <tr>                                    
                                    <td><a id="prd_link" target="_blank" href="#"><span style="font-size:14pt; margin-left:80px;">쇼핑정보 보러가기</span></a></td>
                                </tr>
                    </table>                    
				</div>
				<div style="margin-top:20px;">
					<div style="float:left;">
						<span style="font-size:14pt;">공구시작</span>
						<div class="input-append">
                            <div id="datetime1" class="input-append date">
                            @Html.EditorFor(model => model.JoinDateStart)
                            @Html.ValidationMessageFor(model => model.JoinDateStart)
                            <span class="add-on"><i class="icon-calendar" data-time-icon="icon-time" data-date-icon="icon-calendar"></i></span>						    
                            </div>
						</div>	
					</div>				
				</div>
				<div>
					<div style="float:left;margin-left:20px;">
						<span style="font-size:14pt;">공구종료</span>
                        <div class="input-append">
                            <div id="datetime2" class="input-append date">
                            @Html.EditorFor(model => model.JoinDateEnd)
                            @Html.ValidationMessageFor(model => model.JoinDateEnd)
                            <span class="add-on"><i class="icon-calendar" data-time-icon="icon-time" data-date-icon="icon-calendar"></i></span>						    
                            </div>
						</div>	
					</div>
				</div>
				<div style="clear:both;">
				</div>
				<div>
					<div style="float:left">
						<span style="font-size:14pt;">입찰시작</span>
						<div class="input-append">
                            <div id="datetime3" class="input-append date">
                            @Html.EditorFor(model => model.BidDateStart)
                            @Html.ValidationMessageFor(model => model.BidDateStart)
                            <span class="add-on"><i class="icon-calendar" data-time-icon="icon-time" data-date-icon="icon-calendar"></i></span>
                            </div>
						</div>	
					</div>
				</div>
				<div>
					<div style="float:left">
						<span style="font-size:14pt;margin-left:20px;">입찰종료</span>
						<div class="input-append">
                            <div id="datetime4" class="input-append date">
                            @Html.EditorFor(model => model.BidDateEnd)
                            @Html.ValidationMessageFor(model => model.BidDateEnd)
                            <span class="add-on"><i class="icon-calendar" data-time-icon="icon-time" data-date-icon="icon-calendar"></i></span>
                            </div>
						</div>		
					</div>
				</div>
				<div style="clear:both;">
				</div>	
			</div>
			
			<!-- 에디터는 이쪽으로 -->
			<div>
                @Html.TextAreaFor(model => model.Detail, new { style = "width:100%; height:500px;" })
			</div>
			<div style="width:100px; height:100px; border: 1px solid #ffffff; text-align:center; margin:20px;">
				<input type="submit" class="btn btn-midium btn btn-primary" value="공동구매만들기" />
			</div>
}
		</div>
	</div>    
    <script>
        function formSubmit() {
            var Title = $("#Title");
            var JoinDateStart = $("#JoinDateStart");
            var JoinDateEnd = $("#JoinDateEnd");
            var BidDateStart = $("#BidDateStart");
            var BidDateEnd = $("#BidDateEnd");

            if (Title.val() == "") {
                alert("상품을 선택하세요.");
                window.open("/Goods/APISearch", "_blank", "width=500, height=700, toolbar=no, menubar=no, scrollbars=yes, resizable=no");
                return false;
            }
            if (JoinDateStart.val() == "") {
                alert("공구시작일은 필수값입니다.");
                JoinDateStart.focus();
                return false;
            }
            if (JoinDateEnd.val() == "") {
                alert("공구종료일은 필수값입니다.");
                JoinDateEnd.focus();
                return false;
            }
            if (BidDateStart.val() == "") {
                alert("입찰시작일은 필수값입니다.");
                BidDateStart.focus();
                return false;
            }
            if (BidDateEnd.val() == "") {
                alert("입찰종료일은 필수값입니다.");
                BidDateEnd.focus();
                return false;
            }

            if (JoinDateStart.val() > JoinDateEnd.val()) {
                alert("공구종료일이 공구시작일보다 작을 수 없습니다.");
                JoinDateEnd.focus();
                return false;
            }
            if (BidDateStart.val() > BidDateEnd.val()) {
                alert("입찰종료일이 입찰시작일보다 작을 수 없습니다.");
                JoinDateStart.focus();
                return false;
            }
            if (JoinDateEnd.val() > BidDateEnd.val()) {
                alert("입찰종료일이 공구종료일보다 작을 수 없습니다.");
                JoinDateStart.focus();
                return false;
            }

            return true;
        }

        $(function () {
            $("#goodsSearch").on("click", function () {
                window.open("/Goods/APISearch", "_blank", "width=800, height=700, toolbar=no, menubar=no, scrollbars=yes, resizable=no");
            });

            $.fn.datetimepicker.dates['ko-kr'] = {
                days: ["일", "월", "화", "수", "목", "금", "토", "일"],
                daysShort: ["일", "월", "화", "수", "목", "금", "토", "일"],
                daysMin: ["일", "월", "화", "수", "목", "금", "토", "일"],
                months: ["1월", "2월", "3월", "4월", "5월", "6월", "7월", "8월", "9월", "10월", "11월", "12월"],
                monthsShort: ["1월", "2월", "3월", "4월", "5월", "6월", "7월", "8월", "9월", "10월", "11월", "12월"],
                today: "오늘"
            };
            $("#JoinDateStart").attr("data-format", "yyyy-MM-dd");
            $("#JoinDateStart").mask("9999-99-99");
            $("#datetime1").datetimepicker({ language: 'ko-kr' });

            $("#JoinDateEnd").attr("data-format", "yyyy-MM-dd");
            $("#JoinDateEnd").mask("9999-99-99");
            $("#datetime2").datetimepicker({ language: 'ko-kr' });

            $("#BidDateStart").attr("data-format", "yyyy-MM-dd");
            $("#BidDateStart").mask("9999-99-99");
            $("#datetime3").datetimepicker({ language: 'ko-kr' });

            $("#BidDateEnd").attr("data-format", "yyyy-MM-dd");
            $("#BidDateEnd").mask("9999-99-99");
            $("#datetime4").datetimepicker({ language: 'ko-kr' });

            tinymce.init({ selector: 'textarea' });
        });
    </script>
